/*
Copyright © 2020 Romber Li <romber2001@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config

import (
	"net/http"

	"github.com/romberli/go-util/constant"
)

// global constant
const (
	DefaultCommandName = "das"
	DefaultBaseDir     = constant.CurrentDir
	// daemon
	DefaultDaemon  = false
	DaemonArg      = "--daemon"
	DaemonArgTrue  = "--daemon=true"
	DaemonArgFalse = "--daemon=false"
	// role
	DefaultRole = ServerRole
	ServerRole  = "server"
	AgentRole   = "agent"
	// log
	DefaultLogDir          = "./log"
	DefaultLogFileExt      = ".log.crn"
	DefaultRotateOnStartup = false
	DefaultLogStdout       = false
	MinLogMaxSize          = 1
	MaxLogMaxSize          = constant.MaxInt
	MinLogMaxDays          = 1
	MaxLogMaxDays          = constant.MaxInt
	MinLogMaxBackups       = 1
	MaxLogMaxBackups       = constant.MaxInt
	// server
	DefaultServerAddr                      = "0.0.0.0:6090"
	DefaultServerReadTimeout               = 60
	DefaultServerWriteTimeout              = 60
	MinServerReadTimeout                   = 0
	MaxServerReadTimeout                   = 3600
	MinServerWriteTimeout                  = 0
	MaxServerWriteTimeout                  = 3600
	DefaultServerPProfEnabled              = false
	DefaultServerDeploymentAccessibleZones = constant.EmptyString
	DefaultServerRouterAlternativeBasePath = constant.EmptyString
	DefaultServerRouterAlternativeBodyPath = constant.EmptyString
	DefaultServerRouterHTTPErrorCode       = http.StatusInternalServerError
	// db
	DefaultDBName                  = "das"
	DefaultDBUser                  = "root"
	DefaultDBPass                  = "root"
	MinDBPoolMaxConnections        = 1
	MaxDBPoolMaxConnections        = constant.MaxInt
	MinDBPoolInitConnections       = 1
	MaxDBPoolInitConnections       = constant.MaxInt
	MinDBPoolMaxIdleConnections    = 1
	MaxDBPoolMaxIdleConnections    = constant.MaxInt
	MinDBPoolMaxIdleTime           = 1
	MaxDBPoolMaxIdleTime           = constant.MaxInt
	MinDBPoolMaxWaitTime           = -1
	MaxDBPoolMaxWaitTime           = constant.MaxInt
	MinDBPoolMaxRetryCount         = -1
	MaxDBPoolMaxRetryCount         = constant.MaxInt
	MinDBPoolKeepAliveInterval     = 1
	MaxDBPoolKeepAliveInterval     = constant.MaxInt
	DefaultDBMonitorPrometheusUser = "admin"
	DefaultDBMonitorPrometheusPass = "admin"
	DefaultDBMonitorClickhouseUser = constant.EmptyString
	DefaultDBMonitorClickhousePass = constant.EmptyString
	DefaultDBMonitorMySQLUser      = "root"
	DefaultDBMonitorMySQLPass      = "root"
	DefaultDBApplicationMySQLUser  = "root"
	DefaultDBApplicationMySQLPass  = "root"
	// privilege
	DefaultPrivilegeEnabled       = true
	DefaultPrivilegeSpecialTokens = constant.EmptyString
	// metadata
	MetadataUserDeveloperRole          = 1
	MetadataUserDBARole                = 2
	MetadataUserAdminRole              = 3
	MinMetadataTableAnalyzeMinRole     = MetadataUserDeveloperRole
	MaxMetadataTableAnalyzeMinRole     = MetadataUserAdminRole
	DefaultMetadataTableAnalyzeMinRole = MetadataUserDBARole
	// alert
	DefaultAlertSMTPEnabled = true
	AlertSMTPTextFormat     = "text"
	AlertSMTPHTMLFormat     = "html"
	DefaultAlterSMTPFormat  = AlertSMTPTextFormat
	DefaultAlertSMTPURL     = "127.0.0.1:25"
	DefaultAlertSMTPUser    = "root"
	DefaultAlertSMTPPass    = "root"
	DefaultAlertSMTPFrom    = "mail@example.com"
	DefaultAlertHTTPEnabled = false
	DefaultAlertHTTPURL     = "http://127.0.0.1:8080"
	DefaultAlertHTTPConfig  = "{}"
	// healthcheck
	DefaultHealthCheckBucketCapacity    = 5
	DefaultHealthCheckBucketNum         = 5
	DefaultHealthCheckBucketInterval    = 1
	DefaultHealthCheckBucketMaxWaitTime = 5
	DefaultHealthCheckAllowConcurrent   = false
	DefaultHealthCheckMaxRange          = 7
	// query
	DefaultQueryMinRowsExamined = 100000
	DefaultQueryMinExecTime     = 0.1
	// sqladvisor
	DefaultSQLAdvisorSoarBin       = "./soar"
	DefaultSQLAdvisorSoarTempDir   = "/tmp"
	DefaultSQLAdvisorSoarConfig    = "./soar.yaml"
	DefaultSQLAdvisorSoarBlacklist = "./soar.blacklist"
)

// configuration constant
const (
	// env
	EnvPodNameKey = "MY_POD_NAME"
	// config
	ConfKey = "config"
	// daemon
	DaemonKey = "daemon"
	// role
	RoleKey = "role"
	// log
	LogFileKey            = "log.file"
	LogLevelKey           = "log.level"
	LogFormatKey          = "log.format"
	LogMaxSizeKey         = "log.maxSize"
	LogMaxDaysKey         = "log.maxDays"
	LogMaxBackupsKey      = "log.maxBackups"
	LogRotateOnStartupKey = "log.rotateOnStartup"
	LogStdoutKey          = "log.stdout"
	// server
	ServerAddrKey                      = "server.addr"
	ServerPortKey                      = "server.port"
	ServerPidFileKey                   = "server.pidFile"
	ServerReadTimeoutKey               = "server.readTimeout"
	ServerWriteTimeoutKey              = "server.writeTimeout"
	ServerPProfEnabledKey              = "server.pprof.enabled"
	ServerDeploymentAccessibleZonesKey = "server.deployment.accessibleZones"
	ServerCallbackAddrKey              = "server.callbackAddr"
	ServerRouterAlternativeBasePathKey = "server.router.alternativeBasePath"
	ServerRouterAlternativeBodyPathKey = "server.router.alternativeBodyPath"
	ServerRouterHTTPErrorCodeKey       = "server.router.httpErrorCode"
	// database
	DBDASMySQLAddrKey           = "db.das.mysql.addr"
	DBDASMySQLNameKey           = "db.das.mysql.name"
	DBDASMySQLUserKey           = "db.das.mysql.user"
	DBDASMySQLPassKey           = "db.das.mysql.pass"
	DBPoolMaxConnectionsKey     = "db.pool.maxConnections"
	DBPoolInitConnectionsKey    = "db.pool.initConnections"
	DBPoolMaxIdleConnectionsKey = "db.pool.maxIdleConnections"
	DBPoolMaxIdleTimeKey        = "db.pool.maxIdleTime"
	DBPoolMaxWaitTimeKey        = "db.pool.maxWaitTime"
	DBPoolMaxRetryCountKey      = "db.pool.maxRetryCount"
	DBPoolKeepAliveIntervalKey  = "db.pool.keepAliveInterval"
	DBApplicationMySQLUserKey   = "db.application.mysql.user"
	DBApplicationMySQLPassKey   = "db.application.mysql.pass"
	DBMonitorPrometheusUserKey  = "db.monitor.prometheus.user"
	DBMonitorPrometheusPassKey  = "db.monitor.prometheus.pass"
	DBMonitorClickhouseUserKey  = "db.monitor.clickhouse.user"
	DBMonitorClickhousePassKey  = "db.monitor.clickhouse.pass"
	DBMonitorMySQLUserKey       = "db.monitor.mysql.user"
	DBMonitorMySQLPassKey       = "db.monitor.mysql.pass"
	// privilege
	PrivilegeEnabledKey       = "privilege.enabled"
	PrivilegeSpecialTokensKey = "privilege.specialTokens"
	// metadata
	MetadataTableAnalyzeMinRoleKey = "metadata.table.analyze.minRole"
	// alert
	AlertSMTPEnabledKey = "alert.smtp.enabled"
	AlertSMTPFormatKey  = "alert.smtp.format"
	AlertSMTPURLKey     = "alert.smtp.url"
	AlertSMTPUserKey    = "alert.smtp.user"
	AlertSMTPPassKey    = "alert.smtp.pass"
	AlertSMTPFromKey    = "alert.smtp.from"
	AlertHTTPEnabledKey = "alert.http.enabled"
	AlertHTTPURLKey     = "alert.http.url"
	AlertHTTPConfigKey  = "alert.http.config"
	// healthcheck
	HealthCheckBucketCapacityKey    = "healthcheck.bucket.capacity"
	HealthCheckBucketNumKey         = "healthcheck.bucket.num"
	HealthCheckBucketIntervalKey    = "healthcheck.bucket.interval"
	HealthCheckBucketMaxWaitTimeKey = "healthcheck.bucket.maxWaitTime"
	HealthCheckAllowConcurrentKey   = "healthcheck.allowConcurrent"
	HealthcheckMaxRangeKey          = "healthcheck.maxRange"
	// query
	QueryMinRowsExaminedKey = "query.minRowsExamined"
	QueryMinExecTimeKey     = "query.minExecTime"
	// sqladvisor
	SQLAdvisorSoarBinKey       = "sqladvisor.soar.bin"
	SQLAdvisorSoarTempDirKey   = "sqladvisor.soar.tempDir"
	SQLAdvisorSoarConfigKey    = "sqladvisor.soar.config"
	SQLAdvisorSoarSamplingKey  = "sqladvisor.soar.sampling"
	SQLAdvisorSoarProfilingKey = "sqladvisor.soar.profiling"
	SQLAdvisorSoarTraceKey     = "sqladvisor.soar.trace"
	SQLAdvisorSoarExplainKey   = "sqladvisor.soar.explain"
)
